package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.SpecialBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SpecialMapper {
    /**
     * 查询所有的专栏
     * @return
     */
    @Select("select * from special_info where del=0  ")
    List<SpecialBean> findAll();

    /**
     * 修改状态:下架
     * 0--上架
     * 1--下架
     * @param id
     * @return
     */
    @Update("update  special_info set status=1 where id=#{id}")
    int updateStatus(int id);

    /**
     * 修改状态:上架
     * 0--上架
     * 1--下架
     * @param id
     * @return
     */
    @Update("update  special_info set status=0 where id=#{id}")
    int putaway(int id);

    /**
     * 删除
     * 0--未删除
     * 1--删除
     * @param id
     * @return
     */
    @Update("update  special_info set del=1 where id=#{id}")
    int del(int id);


    /**
     * 模糊查询
     *
     * @param specialBean
     * @return
     */
    List<SpecialBean> findAllByParams(@Param("s") SpecialBean specialBean);


    /**
     * 修改专栏
     *
     * @param specialBean
     * @return
     */
    @Update("<script>" +
            "update special_info" +
            "<set>" +
            "<if test='s.specialName != null'>" +
            " special_name = #{s.specialName}," +
            "</if>" +
            "<if test='s.descr != null'>" +
            " descr = #{s.descr}," +
            "</if>" +
            "<if test='s.fkProjectId != null'>" +
            " fk_project_id = #{s.fkProjectId}," +
            "</if>" +
            "<if test='s.price != null'>" +
            " price = #{s.price}," +
            "</if>" +
            "<if test='s.masterDrawing != null'>" +
            " master_drawing = #{s.masterDrawing}," +
            "</if>" +
            "</set>" +
            "where id = #{s.id}" +
            "</script>")
    int updateSpecial(@Param("s") SpecialBean specialBean);

    /**
     * 创建专栏
     * @param specialBean
     * @return
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "s.id"
    )
    @Insert("insert into special_info " +
            "(special_no,create_time,special_name,video_num,view_counts,status,fk_project_id,master_drawing,descr,content,price,del)" +
            "values(#{s.specialNo},now(),#{s.specialName},#{s.videoNum},#{s.viewCounts},'0',#{s.fkProjectId},#{s.masterDrawing},#{s.descr},#{s.content},#{s.price},'0')")
    int saveColumn(@Param("s") SpecialBean specialBean);


}
